package com.twu.biblioteca.library.item;

import com.twu.biblioteca.control.Strings;

public class Book extends LibraryItem implements Comparable {

    private String author;
    private String userTaken;
    private boolean available;

    public Book(int id, String name, String author) {
        super(id, name);
        this.author = author;
        this.userTaken = "";
        this.available = true;
    }

    public boolean getAvailability() {
        return available;
    }

    public String getAuthor() {
        return author;
    }

    public String getUserTaken() {
        return userTaken;
    }

    public void checkoutBook(String userId){
        this.available = false;
        this.userTaken = userId;
    }

    public void returnBook(){
        this.available = true;
        this.userTaken = "";
    }

    public void getHeader(){
        System.out.println(Strings.bookHeader1);
        System.out.println(Strings.bookHeader2);
        System.out.println(Strings.bookHeader3);
    }

    public void printItem(){
        if(getAvailability()){
            System.out.println(String.format("%8d   %20s   %20s", getId(), getName(), getAuthor()));
        }
    }

    @Override
    public int compareTo(Object object) {
        Book book = (Book) object;
        return Integer.toString( this.getId() ).compareTo( Integer.toString( book.getId() ) );
    }
}
